﻿<Window x:Class="MainWindow" Loaded="Window_Loaded" x:Name="w1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:ProgettoSicurezza.Client"
    Title="Progetto Sicurezza - Client" Height="500" Width="820">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>


        <TextBlock Text="Progetto Sicurezza - Client UI" Margin="5" FontWeight="Bold" FontSize="18" HorizontalAlignment="Center" VerticalAlignment="Center"/>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0 5 5 0">
            <TextBlock Name="tbLogged" Margin="3" Text="Not logged in" FontSize="14" VerticalAlignment="Center"/>
            <Button Name="buttonLogout" Content="Logout" Margin="3" Height="25" Width="80" Click="buttonLogout_Click"/>
        </StackPanel>

        <TabControl Grid.Row="1" Margin="3">
            <TabItem Header="Current Certificates" Name="tabCurrentCerts">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>


                    <GroupBox Margin="3" Header="Digital Signature certificate" VerticalContentAlignment="Center">
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                            <TextBlock x:Name="tbSigCertStatus" Margin="3" TextWrapping="Wrap" HorizontalAlignment="Center" FontSize="14"/>
                            <Button x:Name="buttonSigCertRequest" Margin="3" HorizontalAlignment="Center" Click="buttonSigCertRequest_Click" Height="30" Visibility="{Binding ElementName=w1, Path=ButtonSigCertRequestVisibility}">Request Digital Signature certificate</Button>
                            <Button x:Name="buttonSigCertCheck" Margin="3" HorizontalAlignment="Center" Click="buttonSigCertCheck_Click" Height="30" Visibility="{Binding ElementName=w1, Path=ButtonSigCertCheckVisibility}">Check if certificate is ready</Button>
                            <StackPanel Name="stackSigCertInfo" Orientation="Vertical">
                                <TextBlock Name="tbSigCertExpiration" Margin="3" FontWeight="Bold" FontSize="14"/>
                                <TextBlock Name="tbSigCertSerial" Margin="3" FontWeight="Bold" FontSize="14"/>
                                <StackPanel Name="stackSigRevokeRenew" Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Button Name="ButtonSigView" Content="View certificate details" Height="30" Margin="3" Click="ButtonSigView_Click"/>
                                    <Button Name="ButtonSigRenew" Content="Request renewal" Height="30" Margin="3" Click="ButtonSigRenew_Click" IsEnabled="{Binding ElementName=w1, Path=CanSign}"/>
                                    <Button Name="ButtonSigRevoke" Content="Revoke Certificate" Height="30" Margin="3" Click="ButtonSigRevoke_Click"/>
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>

                    <GroupBox Margin="3" Header="Criptography certificate" Grid.Row="1" VerticalContentAlignment="Center">
                        <StackPanel Orientation="Vertical" VerticalAlignment="Center">
                            <TextBlock x:Name="tbCryptoCertStatus" Margin="3" TextWrapping="Wrap" HorizontalAlignment="Center" FontSize="14"/>
                            <Button x:Name="buttonCryptoCertRequest" Margin="3" HorizontalAlignment="Center" Click="buttonCryptoCertRequest_Click" Height="30" Visibility="{Binding ElementName=w1, Path=ButtonCryptoCertRequestVisibility}" IsEnabled="{Binding ElementName=w1, Path=CanSign}">Request Cryptography certificate</Button>
                            <Button x:Name="buttonCryptoCertCheck" Margin="3" HorizontalAlignment="Center" Click="buttonCryptoCertCheck_Click" Height="30" Visibility="{Binding ElementName=w1, Path=ButtonCryptoCertCheckVisibility}">Check if certificate is ready</Button>
                            <StackPanel Name="stackCryptoCertInfo" Orientation="Vertical">
                                <TextBlock Name="tbCryptoCertExpiration" Margin="3" FontWeight="Bold" FontSize="14"/>
                                <TextBlock Name="tbCryptoCertSerial" Margin="3" FontWeight="Bold" FontSize="14"/>
                                <StackPanel Name="stackCryptoRevokeRenew" Orientation="Horizontal" HorizontalAlignment="Center">
                                    <Button Name="ButtonCryptoView" Content="View certificate details" Height="30" Margin="3" Click="ButtonCryptoView_Click"/>
                                    <Button Name="ButtonCryptoRenew" Content="Request renewal" Height="30" Margin="3" Click="ButtonCryptoRenew_Click" IsEnabled="{Binding ElementName=w1, Path=CanSign}"/>
                                    <Button Name="ButtonCryptoRevoke" Content="Revoke Certificate" Height="30" Margin="3" Click="ButtonCryptoRevoke_Click" IsEnabled="{Binding ElementName=w1, Path=CanSign}"/>
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>


                    <StackPanel Orientation="Vertical" VerticalAlignment="Center" Name="stackGenerating" Visibility="Collapsed">
                        <TextBlock HorizontalAlignment="Center" Text="Genrating keypair..." Margin="3" FontWeight="Bold" FontSize="18"/>
                        <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" Margin="3">
                            Please wait, I'm generating the your RSA Keypair <LineBreak/>
                            This operation could take a while, depending on the keylength you chosed and your CPU...
                        </TextBlock>

                        <ProgressBar IsIndeterminate="True" Width="Auto" Height="25" HorizontalAlignment="Stretch" Margin="30 10"></ProgressBar>
                    </StackPanel>
                </Grid>
            </TabItem>

            <TabItem Header="Old Certificates and CRL" Name="tabOldCerts">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <GroupBox Header="CRL" Margin="3">
                        <DockPanel>
                            <TextBlock Text="CRL status:" Margin="3" VerticalAlignment="Center" FontSize="14" DockPanel.Dock="Left"/>
                            <Button Content="Download latest CRL" Height="30" Margin="3" HorizontalAlignment="Right" DockPanel.Dock="Right" Click="DownloadCRL_Click" IsEnabled="{Binding ElementName=w1, Path=CanSign}"/>
                            <TextBlock Margin="3" FontSize="14" FontWeight="Bold" Name="tbCRLStatus" VerticalAlignment="Center"/>
                        </DockPanel>
                    </GroupBox>

                    <GroupBox Header="Certificates History" Margin="3" Grid.Row="1" >
                        <DataGrid Name="dg" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True" VerticalScrollBarVisibility="Auto">
                            <DataGrid.Columns>

                                <DataGridTemplateColumn Header="Serial n°" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding ID}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                                <DataGridTemplateColumn Header="Valid from" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Certificate.NotBefore}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                                <DataGridTemplateColumn Header="Valid until" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Certificate.NotAfter}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                                <DataGridTemplateColumn Header="Type" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding CertificateType}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2"/>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                                <DataGridTemplateColumn Header="Details" IsReadOnly="True">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2">
                                                <Button Content="Show details" Margin="2" Click="ButtonOldCertDetails_Click"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>

                                <DataGridTemplateColumn Header="Action" IsReadOnly="True" Width="*">
                                    <DataGridTemplateColumn.CellTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5 2">
                                                <Button Content="Check against CRL" Margin="2" Click="ButtonOldCertCheckCRL_Click" IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MainWindow}}, Path=IsCRLReady}"/>
                                                <Button Content="Check via OCSP" Margin="2" Click="ButtonOldCertCheckOCSP_Click" IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MainWindow}}, Path=CanSign}"/>
                                            </StackPanel>
                                        </DataTemplate>
                                    </DataGridTemplateColumn.CellTemplate>
                                </DataGridTemplateColumn>
                            </DataGrid.Columns>
                        </DataGrid>
                    </GroupBox>
                </Grid>
            </TabItem>

            <TabItem Name="tabPdf" Header="PDF Tools"/>
        </TabControl>
    </Grid>
</Window>
